define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'news/category/index',
                    add_url: 'news/category/add',
                    edit_url: 'news/category/edit',
                    del_url: 'news/category/del',
                    multi_url: 'news/category/multi',
                    table: 'category',
                    dragsort_url: '',
                },
                showExport: false
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh DESC, id desc',
                columns: [
                    [
                        { field: 'id', title: __('Id') },
                        { field: 'name', title: __('Name'), operate: false },
                        { field: 'en_name', title: __('En name'), operate: false },
                        { field: 'weigh', title: __('Weigh'), sortable: true, operate: false },
                        {
                            field: 'status',
                            title: __('Status'),
                            align: 'center',
                            formatter: Table.api.formatter.toggle,
                            searchList: { 0: __('Hide'), 1: __('Normal') }
                        },
                        { field: 'create_time', title: __('create time'),operate: false, addclass: 'datetimerange', datetimeFormat: 'YYYY-MM-DD' },
                        {
                            field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            this.api.bindevent();
        },
        edit: function () {
            this.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
        }
    };

    return Controller;
});